Path: blob/master/Part 5 - Association Rule Learning/Apriori/[Phython] Apriori.ipynb
1341 views
Kernel: Python 3
Apriori
Data preprocessing
In [1]:
In [2]:
In [3]:
Out[3]:
In [4]:
In [5]:
Out[5]:
['shrimp',
'almonds',
'avocado',
'vegetables mix',
'green grapes',
'whole weat flour',
'yams',
'cottage cheese',
'energy drink',
'tomato juice',
'low fat yogurt',
'green tea',
'honey',
'salad',
'mineral water',
'salmon',
'antioxydant juice',
'frozen smoothie',
'spinach',
'olive oil']
In [6]:
Out[6]:
list
In [7]:
Out[7]:
7501
Training Apriori on the dataset
In [8]:
Visualization of the result
In [9]:
In [10]:
Out[10]:
RelationRecord(items=frozenset({'cottage cheese', 'brownies'}), support=0.0034662045060658577, ordered_statistics=[OrderedStatistic(items_base=frozenset({'brownies'}), items_add=frozenset({'cottage cheese'}), confidence=0.10276679841897232, lift=3.225329518580382), OrderedStatistic(items_base=frozenset({'cottage cheese'}), items_add=frozenset({'brownies'}), confidence=0.10878661087866107, lift=3.2253295185803816)])
In [11]:
Out[11]:
['__add__',
'__class__',
'__contains__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__getnewargs__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__module__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__rmul__',
'__setattr__',
'__sizeof__',
'__slots__',
'__str__',
'__subclasshook__',
'_asdict',
'_fields',
'_make',
'_replace',
'_source',
'count',
'index',
'items',
'ordered_statistics',
'support']
In [12]:
Out[12]:
['__add__',
'__class__',
'__contains__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__getitem__',
'__getnewargs__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__iter__',
'__le__',
'__len__',
'__lt__',
'__module__',
'__mul__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__rmul__',
'__setattr__',
'__sizeof__',
'__slots__',
'__str__',
'__subclasshook__',
'_asdict',
'_fields',
'_make',
'_replace',
'_source',
'confidence',
'count',
'index',
'items_add',
'items_base',
'lift']
In [13]:
Out[13]:
association: frozenset({'cottage cheese', 'brownies'})
support: 0.0034662045060658577
confidence: 0.10276679841897232
lift: 3.225329518580382
association: frozenset({'light cream', 'chicken'})
support: 0.004532728969470737
confidence: 0.07555555555555556
lift: 4.843950617283951
association: frozenset({'escalope', 'mushroom cream sauce'})
support: 0.005732568990801226
confidence: 0.0722689075630252
lift: 3.7908326967150496
association: frozenset({'escalope', 'pasta'})
support: 0.005865884548726837
confidence: 0.07394957983193277
lift: 4.700811850163794
association: frozenset({'fresh bread', 'tomato juice'})
support: 0.004266097853619517
confidence: 0.09907120743034055
lift: 3.2593558198902826
association: frozenset({'fresh tuna', 'honey'})
support: 0.003999466737768298
confidence: 0.17964071856287428
lift: 3.7850703088205613
association: frozenset({'fromage blanc', 'honey'})
support: 0.003332888948140248
confidence: 0.2450980392156863
lift: 5.164270764485569
association: frozenset({'ground beef', 'herb & pepper'})
support: 0.015997866951073192
confidence: 0.1628222523744912
lift: 3.291993841134928
association: frozenset({'ground beef', 'tomato sauce'})
support: 0.005332622317024397
confidence: 0.054274084124830396
lift: 3.840659481324083
association: frozenset({'olive oil', 'light cream'})
support: 0.003199573390214638
confidence: 0.20512820512820515
lift: 3.1147098515519573
association: frozenset({'olive oil', 'whole wheat pasta'})
support: 0.007998933475536596
confidence: 0.12145748987854252
lift: 4.1224100976422955